package zkk.com.mengqu.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import cn.smssdk.SMSSDK;
import zkk.com.mengqu.R;

/**
 * Created by Administrator on 2017/4/1.
 * 验证码登录界面
 */
public class LoginCodeActivity extends Activity implements View.OnClickListener{
    private Context context;
    private ImageView ivLogin;
    private Button login;
    private TextView register,loginAccount , sendCode;
    private ImageButton btnWeChat , btnTencent , btnAliPay;//微信登录，腾讯登录，支付宝登录
    private EditText etPhone;//editText手机号、验证码
    private String phone;

    private CountDownTimer timer = new CountDownTimer(60*1000 , 1000) {
        @Override
        public void onTick(long millisUntilFinished) {
            sendCode.setEnabled(false);
            sendCode.setText(millisUntilFinished / 1000 + "秒后可重发");
        }

        @Override
        public void onFinish() {
            sendCode.setEnabled(true);
            sendCode.setText(R.string.login_send_code);
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_code);
        initView();
    }

    public void initView(){
        context = getApplicationContext();
        ivLogin = (ImageView)findViewById(R.id.iv_back);
        register = (TextView) findViewById(R.id.tx_register);
        loginAccount = (TextView) findViewById(R.id.tx_login_account);
        sendCode = (TextView) findViewById(R.id.tx_send_code);
        login = (Button) findViewById(R.id.btn_login);

        btnWeChat = (ImageButton)findViewById(R.id.btn_wechat);
        btnTencent = (ImageButton)findViewById(R.id.btn_tencent);
        btnAliPay = (ImageButton)findViewById(R.id.btn_alipay);

        etPhone = (EditText)findViewById(R.id.et_user_phone);

        //添加下划线
        register.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
        register.getPaint().setAntiAlias(true);//抗锯齿

        ivLogin.setOnClickListener(this);
        register.setOnClickListener(this);
        loginAccount.setOnClickListener(this);
        sendCode.setOnClickListener(this);
        login.setOnClickListener(this);

        btnWeChat.setOnClickListener(this);
        btnTencent.setOnClickListener(this);
        btnAliPay.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_back://返回
                finish();
                break;
            case R.id.tx_register:
                startActivity(new Intent(this , RegisterActivity.class));
                break;
            case R.id.tx_login_account://跳转密码登录
                startActivity(new Intent(this, LoginActivity.class));
                finish();
                break;
            case R.id.tx_send_code://发送验证码
                phone = etPhone.getText().toString().trim();
                if(phone.length() != 0){
                    SMSSDK.getVerificationCode("86",phone);//Mob 的发送验证码API
                    timer.start();
                    Toast.makeText(context , R.string.been_send , Toast.LENGTH_LONG).show();
                }else {
                    Toast.makeText(context , R.string.phone_is_null , Toast.LENGTH_LONG).show();
                }
                break;
            case R.id.btn_login://登录
                Toast.makeText(this, "验证码登录", Toast.LENGTH_LONG).show();
                break;
            case R.id.btn_wechat://跳转第三方登录--微信
                Toast.makeText(this , "微信登录" , Toast.LENGTH_LONG).show();
                break;
            case R.id.btn_tencent://跳转第三方登录--腾讯
                Toast.makeText(this , "腾讯登录" , Toast.LENGTH_LONG).show();
                break;
            case R.id.btn_alipay://跳转第三方登录--支付宝
                Toast.makeText(this , "支付宝登录" , Toast.LENGTH_LONG).show();
                break;
            default:
                Toast.makeText(this , "未知点击" , Toast.LENGTH_LONG).show();
                break;
        }
    }
}
